package cn.kgc.ssm.web.controller;

import cn.hutool.captcha.LineCaptcha;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * @author 课工场
 * @date 2024/7/29
 * @description
 */
@Controller
@RequestMapping("captcha")
public class CaptchaController {

    @GetMapping
    public void createCaptcha(HttpServletRequest request, HttpServletResponse response) throws Exception{

        // 验证码的生成
        LineCaptcha lineCaptcha = new LineCaptcha(110, 50, 4, 3);
        String code = lineCaptcha.getCode();
        HttpSession session = request.getSession();
        session.setAttribute("code",code);   //  存储验证码  用于后续用户的认证操作

        ServletOutputStream outputStream = response.getOutputStream();
        lineCaptcha.write(outputStream);
        outputStream.close();
    }

}
